<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 */

include_once("class/upload.class.php");
include_once("class/files.class.php");
include_once("class/history.class.php");

if ($param['op']=='confirm') {
	$upload = new upload;
	$upload->id=$param['fileid'];
	$loader->get($upload);
	$loader->update($upload);
	
	sendFileMail($upload,UPLOAD_PATH."/".$upload->id,$param['comment'],$CURRENT_USER);
	
	foreach ($upload->filesid as $fid) {
		$file = new files($upload->projectid);
		$file->id=$fid;
		$ret = $loader->get($file);
		if ($ret) {
			$file->statusid = FILE_STATUS_CMPND;
			$file->userid = $CURRENT_USER->userid;
			$file->auto = 1;
			$file->comment = $param['comment'];
			$file->stamp=util::hashcode($file->id);
			$loader->update($file);
	
			$his = new history($upload->projectid);
			$his->statusid=$file->statusid;
			$his->fileid=$file->id;
			$his->userid=$CURRENT_USER->userid;
			$his->comment=$file->comment;
			$loader->save($his);
		}
	}
	include("includes/list.php");
} elseif ($param['op']=='upload') {
	include("includes/upfile.php");
} else {
	if ($param['op']=="error") $error = $LANG['uploaderror']; 
	$content=$tm->fetch("fileupload.tpl");	
}

?>
